package com.baiyinet.ui.share;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.baiyinet.R;

/**
 * Created by developer on 17-4-13.
 */

public class ShareItemAdapter extends BaseAdapter {
    Context context;

    public ShareItemAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return ShareLinkDialogActivity.iconIds.length;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        View convertView;
        ViewHolder holder;
        if (view == null) {
            convertView = View.inflate(context, R.layout.item_share,null);
            holder = new ViewHolder();
            convertView.setTag(holder);
        }else {
            convertView = view;
            holder = (ViewHolder) convertView.getTag();
        }

        holder.ivIcon = (ImageView) convertView.findViewById(R.id.item_share_icon);
        holder.tvText = (TextView) convertView.findViewById(R.id.item_share_text);
        holder.viewLine = convertView.findViewById(R.id.item_share_line);

        holder.ivIcon.setBackgroundResource(ShareLinkDialogActivity.iconIds[i]);
        holder.tvText.setText(ShareLinkDialogActivity.shareTexts[i]);

        if (i == ShareLinkDialogActivity.iconIds.length - 1) {

            holder.viewLine.setVisibility(View.INVISIBLE);
        }else {

            holder.viewLine.setVisibility(View.VISIBLE);
        }


        return convertView;
    }


    private class ViewHolder {
        ImageView ivIcon;
        TextView tvText;
        View viewLine;
    }

}
